﻿@{
    ViewData["Title"] = "新建表";
}
<div class="layui-layout layui-layout-admin">
    <form class="layui-form" action="" lay-filter="val-filter">
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block">
                <input type="hidden" name="tableName" value="" />
                <input type="hidden" name="configId" value="1300000000001" />
                <input type="text" name="dbColumnName" autocomplete="off" lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea name="columnDescription" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">自增</label>
                <div class="layui-input-inline">
                    <select name="isIdentity">
                        <option value="0">否</option>
                        <option value="1">是</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-inline">
                    <select name="dataType">
                        <option value="text">text</option>
                        <option value="varchar">varchar</option>
                        <option value="nvarchar">nvarchar</option>
                        <option value="char">char</option>
                        <option value="nchar">nchar</option>
                        <option value="timestamp">timestamp</option>
                        <option value="int">int</option>
                        <option value="smallint">smallint</option>
                        <option value="tinyint">tinyint</option>
                        <option value="bigint">bigint</option>
                        <option value="bit">bit</option>
                        <option value="decimal">decimal</option>
                        <option value="datetime">datetime</option>
                        <option value="date">date</option>
                        <option value="blob">blob</option>
                        <option value="clob">clob</option>
                    </select>
                </div>
            </div>                        
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">主键</label>
                <div class="layui-input-inline">
                    <select name="isPrimarykey">
                        <option value="0">否</option>
                        <option value="1">是</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">可空</label>
                <div class="layui-input-inline">
                    <select name="isNullable">
                        <option value="0">否</option>
                        <option value="1">是</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">长度</label>
                <div class="layui-input-inline">
                    <input type="number" value="0" lay-affix="number" name="length" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">小数位</label>
                <div class="layui-input-inline">
                    <input type="number" value="0" lay-affix="number" name="decimalDigits" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>        
    </form>
</div>

@section scripts {
    <script type="text/javascript">
        var app = {};
        layui.use(['http', 'toast'], function () {
            var $ = layui.$, form = layui.form,
                http = layui.http, toast = layui.toast;
            //
            app.init = function () {
                let data = app.data || {};
                form.val('val-filter', data);
            }();
            app.save = function () {
                form.submit('val-filter', function (data) {                 
                    var postData = data.field
                    //
                    http.post('/api/sysDatabase/addColumn', postData).then((res) => {
                        if (res.code == 200) {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.app.loadColumns();
                            toast.success({ message: '保存成功！' });
                        }
                        else {
                            layer.alert('保存失败，错误信息:' + res.message, { icon: 2 });
                        }
                    });

                    return false;
                });
            }
        })
    </script>
}
